package com.vincent.testall.controller;

import com.vincent.testall.dao.UserRoleDao;
import com.vincent.testall.po.UserRole;
import com.vincent.testall.po.UserRoleExample;
import com.vincent.testall.service.TestService;
import com.vincent.testall.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    TestService testService;

    @Autowired
    UserRoleDao userRoleDao;

    @RequestMapping("testAysnc")
    public ResponseResult<String> testAysnc(){

        System.out.println(Thread.currentThread().getName());
        testService.testAsync();
        return ResponseResult.success(null,null);
    }

    @RequestMapping("monitor")
    public ResponseResult<String> monitor() throws Exception{
        Thread.sleep(1000*30);
        return ResponseResult.success("ok", "current service is ok");
    }

    @RequestMapping("testOOM")
    public ResponseResult<String> testOOM(){
        List<Object> list =new ArrayList<>();
        for (int i=0;i<Integer.MAX_VALUE;i++){
            list.add(new Object());
        }
        return ResponseResult.success(null, null);
    }

    @RequestMapping("testUpdate")
    public ResponseResult<String> testUpdate() throws Exception{

        //UserRole id = userRoleDao.selectByPrimaryKey(11);
        UserRole ur= new UserRole();
        ur.setId(12);
        ur.setDescription("123");
        userRoleDao.updateByPrimaryKeySelective(ur);
        return ResponseResult.success("ok", "current service is ok");
    }

    @RequestMapping("testList")
    public ResponseResult<String> testList() throws Exception{

        UserRole id = userRoleDao.selectByPrimaryKey(11);
        return ResponseResult.success("ok", "current service is ok");
    }
}
